/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package PaqueteServelt;

import cl.tienda.modelo.Producto;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Jano_dx
 */
public class ServletCAgrCarrito2 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //Para mostrar la pagina Web
        PrintWriter out = response.getWriter();
        //Obtengo todos los datos de la sesion de usuario
        Vector<Producto> productos = (Vector<Producto>) request.getSession().getAttribute("productos");
        int indice=Integer.parseInt(request.getParameter("indice"));
        Producto prod=productos.get(indice);

        out.println("<html>");
        out.println("<head>");
        out.println("<title>Consultar Producto</title>");
        out.println("<style type=\"text/css\">");
        out.println("<!--");
        out.println("body {");
        out.println("background-color: #FFFF99;");
        out.println("}");
        out.println("body,td,th {");
        out.println("font-family: Arial, Helvetica, sans-serif;");
        out.println("}");
        out.println("</style>");
        out.println("</head>");
        out.println("<body>");
        out.println("<table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">");
        out.println("<tr>");
        out.println("<td width=\"84\" bgcolor=\"#FF0000\"><img src=\"img/carritorx8[1].jpg\" width=\"84\" height=\"77\" /></td>");
        out.println("<td width=\"716\" bgcolor=\"#FF0000\"><h1 style=\"color:#FFFFFF\">Carrito de Compas con Vectores y Sesiones</h1></td>");
        out.println("</tr>");
        out.println("<tr align=\"center\">");
        out.println("<td colspan=\"2\">&nbsp;</td>");
        out.println("</tr>");
        out.println("<tr align=\"center\">");
        out.println("<td colspan=\"2\">");
        out.println("<h4><a href=\"ServletCConProd\">Consultar Productos</a> | <a href=\"ServletCAgrCarrito1\">Agregar al Carrito</a> | <a href=\"login.html\">Salir</a></h4></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td colspan=\"2\">&nbsp;</td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td colspan=\"2\">");


        out.println("<form name=\"frmPrincipal\" method=\"post\" action=\"ServletCAgrCarrito3\">");

        out.println("<table width=\"100%\">");
        out.println("<tr>");
        out.println("<td width=\"17%\">Codigo</td>");
        out.println("<td width=\"83%\"><label>");
        out.println("<input type=\"text\" name=\"txtIndice\" id=\"txtIndice\" readonly=\"readonly\" value=\" " + indice + " \" />");
        out.println("</label></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td>Producto</td>");
        out.println("<td><label>");
        out.println("<input type=\"text\" name=\"txtProducto\" id=\"txtProducto\" readonly=\"readonly\" value=\" "
                + prod.getNombreProducto() + " \" />");
        out.println("</label></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td>Stock</td>");
        out.println("<td><input type=\"text\" name=\"txtStock\" id=\"txtStock\" readonly=\"readonly\" value=\" "
                + prod.getStock() +  " \" /></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td>Cantidad Pedir</td>");
        out.println("<td><input name=\"txtCantidad\" type=\"text\" id=\"txtCantidad\" value=\"0\"  /></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td>&nbsp;</td>");
        out.println("<td><label>");
        out.println("<input type=\"submit\" name=\"button\" id=\"button\" value=\"Solicitar\" />");
        out.println("</label></td>");
        out.println("</tr>");
        out.println("</table>");

        out.println("</form>");

        out.println("</td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td colspan=\"2\">&nbsp;</td>");
        out.println("</tr>");
        out.println("</table>");
        out.println("</body>");
        out.println("</html>");

        out.close();
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
